package com.chenye.kafka.kafka;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.annotation.KafkaHandler;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Auther:chenye
 * @Data:2018/4/23
 * @Description:
 */
@Component
public class KafkaCustomer {
    @Value("${spring.application.name}")
    private String applicationName;
    @KafkaListener(topics = {"chenye-topics"})//TODO 如何开启consumer端的 ack 配置listener属性中的ack_mode
    public void sayHi(String data, Acknowledgment ack){
        System.err.println("hello everyOne ,im chenye .   "+data);
        ack.acknowledge();
    }
    @KafkaListener(topics = {"other-topics"})
    public void other(String str){
        System.err.println("others"+str);
    }
    @KafkaListener(topics = {"testTopic"})
    public void other(ConsumerRecord consumerRecord){
        System.err.println(consumerRecord.toString());
    }
    @KafkaListener(topics = {"zipkin-sleuth-topic"})
    public void zipkin(String data, Acknowledgment ack){
        System.err.println(data);
        System.err.println(applicationName);
        ack.acknowledge();
    }
}
